package com.qfedu.edu.payservice.controller;

import com.qfedu.edu.payservice.service.PayService;
import com.qfedu.edu.result.R;
import com.qfedu.edu.vo.PayVo;
import org.jdom.JDOMException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiaobobo
 * @title: PayController
 * @projectName seckill-fy-2401-parent
 * @description: TODO
 * @date 2024/11/14  9:12
 */
@Controller
@RequestMapping("/payservice/pays")
public class PayController {


    @Autowired
    private PayService payService;

    /**
     * 支付
     * @param payVo
     * @return
     */
    @PostMapping("/pay")
    @ResponseBody
    public R pay(PayVo payVo) throws Exception {
        String urlCode = payService.pay(payVo);
        return R.ok().data("urlCode",urlCode);
    }

    /**
     * 微信的服务器通知我们的服务器支付是成功还是失败....
     * @param req
     * @param resp
     */
    @RequestMapping("/weixinPayNotify")
    public void weixinPayNotify(HttpServletRequest req, HttpServletResponse resp) throws IOException, JDOMException {
        payService.weixinPayNotify(req,resp);
    }

    /**
     * 获取支付状态
     * @param orderNumber
     * @return
     */
    @RequestMapping("/getPayStatus")
    @ResponseBody
    public R getPayStatus(String orderNumber){
        Integer status=payService.getPayStatus(orderNumber);
        return R.ok().data("status",status);
    }

}
